<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

</body>
<script>
  var count = {};
  var str = '278hj2k2d2f2s8';
  for (var i = 0; i < str.length; i++){
    if(count[str.charAt(i)]){
      count[str.charAt(i)]++;
    } else {
      count[str.charAt(i)] = 1;
    }
  }

  console.log(count);
</script>
</html>